package com.xieyong.leetcode;

import java.util.ArrayList;

public class Leetcode817 {
    public static void main(String[] args) {
        ListNode head = new ListNode(0);
        head.next = new ListNode(1);
        head.next.next = new ListNode(2);
        head.next.next.next  = new ListNode(3);
        head.next.next.next.next  = null;
        int[] nums = {0,1,3};
        Leetcode817 leetcode = new Leetcode817();
        int i = leetcode.numComponents(head, nums);
        System.out.println(i);
    }

    public int numComponents(ListNode head, int[] nums) {
        int result = 0;
        int count = 0;
        ArrayList<Integer> list = new ArrayList<>();
        for( int i : nums){
            list.add(i);
        }
        while (head != null) {
            if(list.contains(head.val)) {
                if(count == 0) {
                    result++;
                }
                count++;
            } else {
                count = 0;
            }
            head = head.next;
        }
        return result;
    }
}


class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}